<template>
  <views class="company_check">
    <viewTitle :title="'企业审核'"></viewTitle>
    <div class="search">
      <el-form ref="form" label-width="auto" :inline="true">
        <el-form-item label="企业名称:">
          <el-input type="text" clearable placeholder="请输入企业名称" v-model="company_name"></el-input>
        </el-form-item>
        <el-form-item label="企业类型:">
          <el-select v-model="company_type" clearable placeholder="请选择">
            <el-option
                    v-for="item in company_type_list"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="统一社会信用代码:">
          <el-input type="text" clearable placeholder="请输入信用代码" v-model="organization_code"></el-input>
        </el-form-item>
        <el-form-item label="法人姓名:">
          <el-input type="text" clearable placeholder="请输入法人姓名" v-model="legal_person"></el-input>
        </el-form-item>
      </el-form>
      <el-form ref="form" label-width="auto" :inline="true">
        <el-form-item label="法人联系方式:">
          <el-input type="text" clearable placeholder="请输入法人联系方式" v-model="legal_phone"></el-input>
        </el-form-item>
        <el-form-item label="法人身份证号:">
          <el-input type="text" clearable placeholder="请输入身份证号" v-model="legal_card_no"></el-input>
        </el-form-item>
        <el-form-item label="审核状态:">
          <el-select v-model="apply_status" clearable placeholder="请选择">
            <el-option
              v-for="item in apply_status_list"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="注册时间:">
          <el-date-picker
            v-model="registration_date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>

      <div class="btn-area">
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </div>
    </div>
    <div class="table_list">
      <el-table :data="tableList" style="width: 100%" border :header-cell-style="getRowClass">
        <el-table-column type="index" label="序号" width="80"></el-table-column>
<!--        <el-table-column prop="apply_id" label="ID" width="100"></el-table-column>-->
        <el-table-column prop="company_name" label="企业名称" width="180"></el-table-column>
        <el-table-column :formatter="(row) => {return  row.type == 1 ? '快递' : '物流'}" label="企业类型" width="180"></el-table-column>
        <el-table-column prop="organization_code" label="统一社会信用代码" width="200"></el-table-column>
        <el-table-column prop="legal_person" label="法人" width="180"></el-table-column>
        <el-table-column prop="legal_phone" label="法人联系方式" width="150"></el-table-column>
        <el-table-column prop="legal_card_no" label="法人身份证号" width="200"></el-table-column>
        <el-table-column prop="apply_status_name" label="审核状态" width="200"></el-table-column>
        <el-table-column prop="created_time" label="创建时间" width="200"></el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="success" v-if="$route.query.check.q" @click="toDetail(scope.row.apply_id)">详情</el-button>
            <el-button type="warning" v-if="$route.query.check.c && scope.row.apply_status == 0" @click="check(scope.row.apply_id)" >审核</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex flexR paging">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="prev, pager, next,sizes,total, jumper"
          @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
          @current-change="(current_page) => {this.pagination.page_start = current_page;this.getData()}"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>


<script>
export default {
  data() {
    return {
      company_name: "", // 企业名称
      organization_code: "", // 信用代码
      legal_person: "", // 法人名称
      legal_phone: "", // 联系方式
      legal_card_no: "", // 身份证
      apply_status: null, // 审核状态
      apply_status_list: [ {value:null, label:'全部'}, {value:0, label:'申请中'}, {value:1, label:'审核通过'}, {value:2, label:'已驳回'}], // 审核状态
      registration_date: [], // 注册时间
      tableList: [],
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      company_type: null,
      company_type_list: [
        {value:null, label:'全部'},
        {value:0, label:'物流'},
        {value:1, label:'快递'}
      ]
    };
  },
  computed: {
     postData(){
      let post = {};
      post.company_name = this.company_name;
      post.organization_code = this.organization_code;
      post.legal_person = this.legal_person;
      post.legal_phone = this.legal_phone;
      post.legal_card_no = this.legal_card_no;
      if(this.apply_status)  post.apply_status = this.apply_status;
      if(this.registration_date.length > 0){
        post.start_created_time = this.registration_date[0]/1000;     //开始时间
        post.end_created_time = this.registration_date[1]/1000;     //结束时间
      }
      post.pagination = this.pagination;
      post.type = this.company_type;
      return  post;
    }
  },

  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    // 获取数据
    getData() {
      this.$raxios.post(this.$mapapi.companyApplyList, {data:this.postData}).then(res=>{
      if(res.code==200){
       this.tableList = res.data.list;
       this.pagination = res.data.pagination;
        }else{
           this.pagination = [];
          this.tableList = [];
	      this.$message.error(res.msg)
        }
      })
    },


    // 去详情
    toDetail(apply_id) {
      this.$toRoutePath({
        path: "/company_check/company_check_detail",
        edit: true,
        query: { type: 1 , apply_id}
      });
    },
    // 审核
    check(apply_id) {
      this.$toRoutePath({
        path: "/company_check/company_check_detail",
        edit: true,
        query: { type: 2 , apply_id}
      });
    },
    // 重置
    reset() {
      this.company_name = ""; // 企业名称
      this.organization_code = ""; // 信用代码
      this.legal_person = ""; // 法人名称
      this.legal_phone = ""; // 联系方式
      this.legal_card_no = ""; // 身份证
      this.apply_status = null; // 审核状态
      this.registration_date = []; // 注册时间
      this.company_type = null; // 企业类型
      this.getData()
    }
  },
  mounted() {
    this.getData();
    console.log("获取路由",this.$route)
  },
  created() {}
};
</script>

<style lang="less" :scope="true"  src="@/style/company_manager/company_check.less">
</style>
